package main

import (
	"fmt"
	"sort"
)

//team implements sort.Interface
type team []string

func (t team) Len() int {
	return len(t)
}
func (t team) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}
func (t team) Less(i, j int) bool {
	return t[i] < t[j]
}

func sortTeam() {

	team1 := team{"Zeno", "John", "Al", "Jenny"}
	sort.Sort(team1)
	fmt.Println(team1)
}

//=======================================================
func sortStringSlice1() {
	s := []string{"Zeno", "John", "Al", "Jenny"}
	sort.Sort(sort.StringSlice(s))
	fmt.Println(s)
}

//=======================================================
func sortStringSlice2() {
	s := []string{"Zeno", "John", "Al", "Jenny"}
	sort.Strings(s)
	fmt.Println(s)
}

//=======================================================
func sortReverse() {
	s := []string{"Zeno", "John", "Al", "Jenny"}
	sort.Reverse(sort.StringSlice(s))
	fmt.Println(s)
	sort.Sort(sort.Reverse(sort.StringSlice(s)))
	fmt.Println(s)

	// for experimentation to understand what's going on:
	// uncomment and experiment with the code below:

	//	sort.Sort(sort.StringSlice(s))
	//	fmt.Println(s)
	//
	//	fmt.Printf("just s: %T\n", s)
	//	s = sort.StringSlice(s)
	//	fmt.Printf("just s: %T\n", s)
	//	t := sort.StringSlice(s)
	//	fmt.Printf("just t: %T\n", t)
	//
	//	fmt.Printf("s converted to StringSlice: %T\n", sort.StringSlice(s))
	////	fmt.Printf("s sorted: %T\n", sort.Sort(sort.StringSlice(s)))
	//	fmt.Printf("s reversed: %T\n", sort.Reverse(sort.StringSlice(s)))
	//	i := sort.Reverse(sort.StringSlice(s))
	//	fmt.Println(i)
	//	fmt.Printf("%T\n", i)
	//	sort.Sort(i)
	//	fmt.Println(s)
}

//=======================================================
func sortIntSlice1() {
	n := []int{7, 4, 8, 2, 9, 19, 12, 32, 3}
	sort.Sort(sort.IntSlice(n))
	fmt.Println(n)
}

//=======================================================
func sortIntSlice2() {
	n := []int{7, 4, 8, 2, 9, 19, 12, 32, 3}
	sort.Ints(n)
	fmt.Println(n)
}

//=======================================================
func reverseIntSlice() {
	n := []int{7, 4, 8, 2, 9, 19, 12, 32, 3}
	sort.Sort(sort.Reverse(sort.IntSlice(n)))
	fmt.Println(n)
}

func main() {
	fmt.Println("sortTeam() ==================")
	sortTeam()
	fmt.Println("sortStringSlice1() ================")
	sortStringSlice1()
	fmt.Println("sortStringSlice2() ===============")
	sortStringSlice2()
	fmt.Println("sortReverse() ===============")
	sortReverse()
	fmt.Println("sortIntSlice1() ==============")
	sortIntSlice1()
	fmt.Println("sortIntSlice2() ==============")
	sortIntSlice2()
	fmt.Println("reverseIntSlice() ==============")
	reverseIntSlice()
	fmt.Println("==========================")

}
